package com.hsurosy.domain.activity.service;

import com.hsurosy.domain.activity.model.entity.MarketProductEntity;
import com.hsurosy.domain.activity.model.entity.TrialBalanceEntity;
import com.hsurosy.domain.activity.service.trial.factory.DefaultActivityStrategyFactory;
import com.hsurosy.types.design.framework.tree.StrategyHandler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author Hsu琛君珩
 * @Date 2025-08-11 4:15
 * @Description 首页营销服务
 * @Version: v1.0.0
 */
@Service
public class IndexGroupBuyMarketServiceImpl implements IIndexGroupBuyMarketService {

    @Resource
    private DefaultActivityStrategyFactory defaultActivityStrategyFactory;

    @Override
    public TrialBalanceEntity indexMarketTrial(MarketProductEntity marketProductEntity) throws Exception {
        // 1. 获取根策略处理器
        StrategyHandler<MarketProductEntity, DefaultActivityStrategyFactory.DynamicContext, TrialBalanceEntity> strategyHandler = defaultActivityStrategyFactory.strategyHandler();
        // 2. 执行整棵规则树
        TrialBalanceEntity trialBalanceEntity = strategyHandler.apply(marketProductEntity, new DefaultActivityStrategyFactory.DynamicContext());
        // 3. 得到试算结果
        return trialBalanceEntity;
    }

}
